package shiro.filter;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.web.filter.authc.UserFilter;

import com.jfinal.kit.JsonKit;

import appbase.utils.HttpResponseKit;
import dshop.AppConst;

public class UserFailHandleFilter extends UserFilter {

	//private static final Logger log = Logger.getLogger(UserFailHandleFilter.class);
	
	protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception 
	{
		/*HttpServletRequest httpRequest = (HttpServletRequest)request;
		if (HttpRequestKit.isAjaxRequest(httpRequest)) 
		{
			
		}
		
		WebUtils.issueRedirect(request, response, "/admin/login");
        return false;*/
        
        Map<String, Object> dataMap = new HashMap<String, Object>();
		
		dataMap.put(AppConst.RESPONSE_KEY_CODE, AppConst.RESPONSE_VALUE_CODE_UNAUTHENTICATION);
		dataMap.put(AppConst.RESPONSE_KEY_MSG, "会话已失效，请重新登录");
		
		String json = JsonKit.toJson(dataMap);
		
		HttpResponseKit.writeJson((HttpServletResponse)response, json);
		
		return false;
    }
	
}
